package com.study.model.pojo.configPojo.responsePojo;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.aspectj.weaver.patterns.ThrowsPattern;

import com.study.model.pojo.HRpojo.EmpTab;
import com.study.model.pojo.HRpojo.PermissionTab;
import com.study.model.pojo.HRpojo.RoleTab;

/**个人信息封装
 * @author 小唐
 * @date  2019年6月27日下午1:43:54
 * 
 */
public class EmpRolePermResult {
  private String empid;

  private String empname;
  //菜单封装
  private Set<OnePermResult> onePermResults = new HashSet<>();
  //按钮封装
  private Set<ThreePermResult> threePermResults = new HashSet<>();

  
  public EmpRolePermResult() {
  }
  
  public EmpRolePermResult(EmpTab empTab) {
      this.empid = empTab.getEmpid();
      this.empname = empTab.getEmpname();
      
//      onePermResults.add(new OnePermResult(0, "el-icon-lx-home", "dashboard", "系统首页"));
      
      //通过用户获得角色
      Set<RoleTab> roles = empTab.getRoleTabs();
      
      //定义一个二级菜单集合，获取到所有的二级菜单，再通过遍历一级菜单，将二级菜单添加到一级菜单
      Set<TwoPermResult> two = new HashSet<>();
      
      for (RoleTab r : roles) {
          //通过角色获得权限
          Set<PermissionTab> perm = r.getPermissionTabs();
          List<String> list=new ArrayList<>();
          
          for (PermissionTab p : perm) {
               if (p.getType() == 1) {
                   //添加一级菜单
                   onePermResults.add(new OnePermResult(p.getPermid(),
                                                         p.getIcon(),
                                                         p.getIndex(),
                                                         p.getTitle()));
                }else if (p.getType() == 2) {
                  //添加二级菜单
                  two.add(new TwoPermResult(p.getPid(), p.getIndex(), p.getTitle()));
                  
                }else if (p.getType() == 3) {
                  //如果是按钮，就添加到权限集合
                  threePermResults.add(new ThreePermResult(p.getPermid(),
                                                            p.getEnvisible(),
                                                            p.getTitle()));
                }
          }
      }
      //遍历一级菜单
      for (OnePermResult on : onePermResults) {
          //遍历二级菜单
          for (TwoPermResult t : two) {
             if (on.getPermid()==t.getPid()) {
                 //将二级菜单保存到一级菜单中
                 on.getTwoPermResult().add(t);
            }
          }
      }
      
  } 

  public String getEmpid() {
    return empid;
  }

  public void setEmpid(String empid) {
    this.empid = empid;
  }

  public String getEmpname() {
    return empname;
  }

  public void setEmpname(String empname) {
    this.empname = empname;
  }

  public Set<OnePermResult> getOnePermResults() {
    return onePermResults;
  }

  public void setOnePermResults(Set<OnePermResult> onePermResults) {
    this.onePermResults = onePermResults;
  }

  public Set<ThreePermResult> getThreePermResults() {
    return threePermResults;
  }

  public void setThreePermResults(Set<ThreePermResult> threePermResults) {
    this.threePermResults = threePermResults;
  }
  
  
}